//
//  RootTabBarViewController.m
//  HuaLang
//
//  Created by iking on 2017/11/20.
//  Copyright © 2017年 iking. All rights reserved.
//

#import "RootTabBarViewController.h"
#import "HomepageViewController.h"
#import "ClassifyViewController.h"
#import "ShoppingCartViewController.h"
#import "MineViewController.h"

@interface RootTabBarViewController ()

@end

@implementation RootTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // tabbar背景颜色
//    [[UITabBar appearance] setBarTintColor:navBarColor];
    
    [self addViewControllerClass:[HomepageViewController class] title:@"首页" imageName:@"Home" selectImage:@"Home-"];
    [self addViewControllerClass:[ClassifyViewController class] title:@"分类" imageName:@"fenlei" selectImage:@"fenlei-"];
    [self addViewControllerClass:[ShoppingCartViewController class] title:@"购物车" imageName:@"dingdan" selectImage:@"dingdan-"];
    [self addViewControllerClass:[MineViewController class] title:@"我的" imageName:@"gerenzhongxin" selectImage:@"gerenzhongxin-"];
    // 字体颜色设置
    NSMutableDictionary *attributes = [NSMutableDictionary dictionary]; attributes[NSForegroundColorAttributeName] = UIColorFromRGB(0x666666); attributes[NSFontAttributeName] = [UIFont systemFontOfSize:10]; NSMutableDictionary *selectAttri = [NSMutableDictionary dictionary]; selectAttri[NSForegroundColorAttributeName] = navBarColor; selectAttri[NSFontAttributeName] = [UIFont systemFontOfSize:10];
    //通过appearance对tabBarItem的文字属性进行统一设置，这样所有的控制的tabBarItem的文字属性久都是这种样式的了
    UITabBarItem *tabbar = [UITabBarItem appearance];
    [tabbar setTitleTextAttributes:attributes forState:UIControlStateNormal];
    [tabbar setTitleTextAttributes:selectAttri forState:UIControlStateSelected];

}
#pragma mark - 添加控制器
- (void)addViewControllerClass:(Class)class title:(NSString *)title imageName:(NSString *)imageName selectImage:(NSString *)selectImage
{
    // 创建一个控制器
    UIViewController *viewC = [[class alloc] init];
    // 设置标题图片 点击图片
    viewC.tabBarItem.image = [UIImage imageNamed:imageName];
    viewC.tabBarItem.selectedImage = [UIImage imageNamed:selectImage];
    // 添加到数组中
    UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:viewC];
    viewC.navigationItem.title = title;
    navVC.tabBarItem.title = title;
    // 显示原图
    navVC.tabBarItem.image = [[UIImage imageNamed:imageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    navVC.tabBarItem.selectedImage = [[UIImage imageNamed:selectImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self addChildViewController:navVC];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
